<template>
  <div>
    <a-row>
      <a-col :span="24">
        <pro-table
          ref="tableRef"
          :pagination="pagination"
          :fetch="fetch"
          :columns="tableConfig.columns"
          :param="state.param"
          :toolbar="toolbar"
          :operate="tableConfig.operate"
        />
        <save v-if="state.visibleSave" ref="savemodal" :parent="state.parentData" :visible="state.visibleSave" @close="closeSave"></save>
      </a-col>
    </a-row>
  </div>
</template>

<script>
import save from "./save-follow";
import { handleFormEmptyData } from "@/tools/filters";
import { reactive, ref, computed } from "vue";
import { useRouter } from "vue-router";
import { delFollowUpRecord } from "@/api/module/school.js";
import { message, Modal } from "ant-design-vue";

export default {
  props: {
    data: {
      type: Array,
      default: () => []
    }
  },
  components: {
    save
  },
  name: "index",

  setup(props, content) {
    const tableRef = ref();
    const savemodal = ref();
    const router = useRouter();
    const pagination = false;
    const tabaleData = computed(() => Array.isArray(props.data.schoolFollowUpRecordList)
              ? props.data.schoolFollowUpRecordList
              : [])
    const columns = [
      {
        dataIndex: "createBy",
        key: "createBy",
        title: "跟进人",
        align: "center"
      },
      {
        dataIndex: "createTime",
        key: "createTime",
        title: "跟进时间",
        align: "center"
      },
      {
        dataIndex: "remark",
        key: "remark",
        title: "备注",
        align: "left"
      },
    ];
    const fetch = param => {
      return {
        data: tabaleData,
      };
    };
    const toolbar = [
      {
        code: "college-manage:add",
        label: "新增",
        type: "primary",
        event: function() {
          state.visibleSave = true;
        }
      }
    ];

    const tableConfig = reactive({
      columns: [
        {
          dataIndex: "createBy",
          key: "createBy",
          title: "跟进人",
          align: "center"
        },
        {
          dataIndex: "createTime",
          key: "createTime",
          title: "跟进时间",
          align: "center"
        },
        {
          dataIndex: "remark",
          key: "remark",
          title: "备注",
          align: "center"
        }
      ],
      operate: [
        {
          code: 'college-manage:follow-remove',
          label: "删除",
          event: (item) => {
            Modal.confirm({
              title: "你需要删除该数据吗？",
              okText: "是",
              okType: "danger",
              cancelText: "否",
              onOk() {
                delFollowUpRecord(item.id).then((response) => {
                  if (response.success) {
                    message.success({ content: "删除成功" });
                    tableRef.value.reload();
                    content.emit('refresh')
                  } else {
                    message.error({ content: "删除失败" });
                  }
                });
              },
            });
          },
        },
      ],
    });
    const goNewSchool = () => router.push("/university/college-manage/add");
    const state = reactive({
      selectedRowKeys: [],
      param: {
        createBy:'',
        createTime:'',
        deleted:'',
        followUpProgressid:'',
        remark: "",
        schId: "",
        updateTime:'',
        updateBy: ""
      },
      visibleSave: false,
      visibleEdit: false,
      visibleInfo: false,
      recordEdit: {},
      recordInfo: {},
      parentData: props.data,
      currentRow: {}
    });
    const closeSave = function(row) {
      state.visibleSave = false;
      tableRef.value.reload();
      content.emit('refresh')
    };
    const onSelectChange = selectedRowKeys => {
      state.selectedRowKeys = selectedRowKeys;
    };

    return {
      columns,
      savemodal,
      fetch,
      closeSave,
      toolbar,
      pagination,
      state,
      tableConfig,
      onSelectChange,
      tableRef,
      handleFormEmptyData,
    };
  }
};
</script>

<style scoped></style>
